package com.hzhr.iot.statis.dao;

import com.hzhr.iot.statis.dao.mapper.custom.DeviceDataExceptionEntityCustomMapper;
import com.hzhr.iot.statis.dao.mapper.generator.DeviceDataExceptionEntityMapper;
import com.hzhr.iot.statis.entity.DeviceDataExceptionEntity;
import com.hzhr.iot.statis.entity.ext.DeviceDataExceptionEntityExt;
import com.hzhr.iot.statis.queryModel.DeviceDataExceptionQueryModel;
import com.hzhr.iot.statis.queryModel.custom.DeviceDataExceptionCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class DeviceDataExceptionDao {
    @Autowired
    DeviceDataExceptionEntityMapper deviceDataExceptionEntityMapper;
    @Autowired
    DeviceDataExceptionEntityCustomMapper deviceDataExceptionEntityCustomMapper;

    public int insert(DeviceDataExceptionEntity record) {
        if (record == null) return 0;
        int changeCount = deviceDataExceptionEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(DeviceDataExceptionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deviceDataExceptionEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(DeviceDataExceptionEntity record) {
        if (record == null) return 0;
        int changeCount = deviceDataExceptionEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(DeviceDataExceptionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deviceDataExceptionEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public DeviceDataExceptionEntity selectEntity(DeviceDataExceptionQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceDataExceptionEntityExt> extList = deviceDataExceptionEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeviceDataExceptionEntity> selectEntityList(DeviceDataExceptionQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceDataExceptionEntityExt> extList = deviceDataExceptionEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<DeviceDataExceptionEntity> entityList = new ArrayList<>();
        for (DeviceDataExceptionEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public DeviceDataExceptionEntityExt selectExt(DeviceDataExceptionQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceDataExceptionEntityExt> extList = deviceDataExceptionEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeviceDataExceptionEntityExt> selectExtList(DeviceDataExceptionQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceDataExceptionEntityExt> extList = deviceDataExceptionEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(DeviceDataExceptionQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = deviceDataExceptionEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
